<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of report
 *
 * @author Константин Охотник
 */
class SomeProductModel extends Crud
{
    private $_listproduct;
    
    public function __construct()
    {
        parent::__construct();
    }

    /*===============================Данные по заказу================================*/  
    public function getProductData($id)
    {
        $r = $this->get_one('tb_product', 'id', $id);
        foreach($r as $key =>$value)
        {
            $person =  $this->get_one('tb_person', 'id', $value['id_person']);
            if(empty($person))
            {
                $r[$key]['person'] = 'Пользователь удалён';
            }
            else
            {
                $r[$key]['person'] = $person[0]['name']." ".$person[0]['first_name']." ".$person[0]['second_name'];
            }
            $category = $this->get_one('gl_categories', 'id', $value['id_category']);
            $r[$key]['category'] = $category[0]['name'];
            $fabricator = $this->get_one('tb_fabricator', 'id', $value['id_fabricator']);
            $r[$key]['fabricator'] = $fabricator[0]['name'];
        }
        return $r;
    }
    
    /*===============================Все категории=================================*/ 
    public function getCategory()
    {
        return $this->get_array('gl_categories');
    }
  
    /*===============================Все производители=============================*/
    public function getFabricator()
    {
       return $this->get_array('tb_fabricator');
    }
    
    /*===============Продукты соответс производителю и категории===================*/
    public function getProduct()
    {
        return $this->_listproduct->result_array();
    }
    
    /*=================================Все сайты===================================*/
    public function getSite()
    {
        return $this->get_array('gl_site');
    }
    /*===============================Список заказов================================*/   
    public function getReport($id)
    {
       $r['count_order'] = count($this->getOrderData($id));
       $q =  $this->getOrderData($id);   
       
       $r['total_cost'] = 0;
       foreach($q as $key => $value)
       {
            $temp = $this->get_one('tb_product', 'id', $value['id_product']);
            $r['total_cost']+= (float)$temp[0]['price'];
       }
       return $r;
    }
}